<?php
class Controller_Admin_Notice extends Controller_Form
{
    public function __construct ($req, $res)
    {
        $this->_form_type = 'notice';
        parent::__construct($req, $res);

        $this->_list_where = array(
//            array('status', '=', 'VALID'),
        );
    }

    public function action_demo ()
    {
    }

    public function action_index ($page = 1)
    {
        $this->action_list($page);
    }

    public function action_list($page = 1){
        $page     = max(1, $page);
        $limit    = 10;
        $offset   = $limit * ($page - 1);


        list($counts,$data) = Util_Notice::notice_list($limit,$offset);

        $pagination = $this->pagination($counts, $limit);
        $this->template->set('pagination', $pagination);
        $this->template->set('data', $data);

        $this->template->set_filename('smarty:/admin/notice_list/list');
    }



    public function action_create ()
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            Util_Notice::addNotice(-10,0,$post['message']);
            $this->to_url('list');
        }else{
            $this->template->set_filename('smarty:/admin/notice_list/add');
        }

    }

    public function action_update ($nid)
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $data['message'] = Arr::get($post,'message');
            Util_Notice::update($data,'id',Arr::get($post,'id'));
            $this->to_url('list');
        }
        else
        {
            $data = Util_Notice::getNoticeById($nid);
            $this->template->set('notices',$data);
            $this->template->set_filename('smarty:/admin/notice_list/edit');
        }

//        parent::action_update($nid);
    }

    public function action_delete ($nid)
    {

       Util_Notice::remove($nid);
        $this->to_url('list');
    }

    public function action_detail ($nid)
    {
        $data = Form_Data::detail($this->_form_type, $nid); 

        $this->_form_data = $data;
        parent::action_detail($nid);
    }

    private function rebuild_post_data (& $post)
    {
        //
        $post['managerUid'] = user::current_user_id();

        $post['images'] = implode('|', $post['images']);

        // 起始时间
    }

    public function list_filter_data (& $rows)
    {
        foreach ($rows as & $rs)
        {
        //    $rs['type'] = App_Config::getLabelString($rs['type'], 'array');
        }
    }


    public function classname_by_list_row (& $row)
    {
    }

    public function actions_by_list_row (& $row, & $menus)
    {
	    $controller = Request::initial()->controller();
	    $directory  = Request::initial()->directory();
	
	    $directory  = empty($directory) ? '' : '/'.$directory;
    }
}


